package setting

import (
	"context"

	"mall/service/forum/rpc/internal/svc"
	"mall/service/forum/rpc/types/forum"

	"github.com/zeromicro/go-zero/core/logx"
)

type BackendSetPageSettingLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBackendSetPageSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BackendSetPageSettingLogic {
	return &BackendSetPageSettingLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BackendSetPageSettingLogic) BackendSetPageSetting(in *forum.BackendSetPageSettingReq) (*forum.BaseResp, error) {
	if in.Key == nil || in.Setting == nil {
		return &forum.BaseResp{}, nil
	}

	_, err := l.svcCtx.User.SetPageSetting(l.ctx, nil, *in.Key, *in.Setting)
	if err != nil {
		return nil, err
	}

	return &forum.BaseResp{}, nil
}
